home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Example Projects / Techniques / Examples by Thomas Tempelmann / TT's Icons-Plugin / Source Code (CW Pro 3) / Plugin SDK v3 Includes / PluginMain.cpp next >
Encoding:
C/C++ Source or Header  |  1999-03-20  |  31.7 KB  |  899 lines

  1. #include "REALplugin.h"
  2. #ifndef WIN32
  3. #include <A4Stuff.h>
  4. #include <SetupA4.h>
  5. #endif
  6. #include "rb_plugin.h"
  7.  
  8. #ifndef WIN32
  9. #ifndef powerc
  10. #define USECALLSHELL
  11. #endif
  12. #endif
  13.  
  14. static void *(*gResolver)(const char *entryName);
  15.  
  16. #ifdef powerc
  17. static void *(*gResolverPPC)(const char *entryName);
  18. #endif
  19.  
  20. // static Ptr *gA4Stack;
  21. static unsigned long a4stack;
  22.  
  23. #ifdef powerc
  24. int __procinfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4));
  25. #endif
  26.  
  27. #ifdef powerc
  28. //#define CallResolver(a) CallUniversalProc((RoutineDescriptor *) gResolver, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)), a)
  29. //#define Caller(func, upp) CallUniversalProc((RoutineDescriptor *) func, upp, 
  30. #define CallResolver(a) gResolverPPC(a)
  31. #else
  32. #define CallResolver(a) gResolver(a)
  33. #endif
  34.  
  35. #ifdef USECALLSHELL
  36. static REALproc buildEnvironmentShell(void *func)
  37. {
  38.     short *glue;
  39.     REALproc proc;
  40.     unsigned long originalCode;
  41.     unsigned long unglue;
  42.     unsigned long pluginA4 = GetCurrentA4();
  43.  
  44.     static int gRemainAllocCount;
  45.     static Ptr gRemainAllocPtr;
  46.  
  47.     if (!func)
  48.         return nil;
  49.     if (func == REALstandardGetter)
  50.         return REALstandardGetter;
  51.  
  52.     originalCode = (unsigned long) func;
  53.     if (!gRemainAllocCount)
  54.     {
  55.         gRemainAllocCount = 8;
  56.         gRemainAllocPtr = NewPtr(8 * 52);
  57.     }
  58.     
  59.     glue = (short *) gRemainAllocPtr;
  60.     gRemainAllocPtr += 52;
  61.     gRemainAllocCount--;
  62.     proc = (REALproc) glue;
  63.  
  64.     unglue = (unsigned long) (glue + 17);
  65.  
  66.     *glue++ = 0x2079; // movea.l $, A0
  67.     *glue++ = a4stack >> 16;
  68.     *glue++ = a4stack & 0xffff;
  69.     *glue++ = 0x210c; // move.l A4, -(A0)
  70.     *glue++ = 0x211f; // move.l (A7)+, -(A0)
  71.     *glue++ = 0x287c; // move.l #, A4
  72.     *glue++ = pluginA4 >> 16;
  73.     *glue++ = pluginA4 & 0xffff;
  74.     *glue++ = 0x2f3c; // move.l #, -(A7)
  75.     *glue++ = unglue >> 16;
  76.     *glue++ = unglue & 0xffff;
  77.     *glue++ = 0x23c8; // move.l A0, $
  78.     *glue++ = a4stack >> 16;
  79.     *glue++ = a4stack & 0xffff;
  80.     *glue++ = 0x4ef9; // jmp $
  81.     *glue++ = originalCode >> 16;
  82.     *glue++ = originalCode & 0xffff;
  83.  
  84.     *glue++ = 0x2279; // movea.l $, A1
  85.     *glue++ = a4stack >> 16;
  86.     *glue++ = a4stack & 0xffff;
  87.     *glue++ = 0x2f19; // move.l (A1)+,-(A7)
  88.     *glue++ = 0x2859; // movea.l (A1)+, A4
  89.     *glue++ = 0x23c9; // move.l A1, $
  90.     *glue++ = a4stack >> 16;
  91.     *glue++ = a4stack & 0xffff;
  92.     *glue++ = 0x4e75; // rts
  93.  
  94.     return proc;
  95. }
  96. #endif
  97.  
  98. #ifndef WIN32
  99. QDGlobals *REALQDGlobals(void)
  100. {
  101.     static QDGlobals *(*pREALQDGlobals)(void);
  102.     if (!pREALQDGlobals)
  103.         pREALQDGlobals = (QDGlobals *(*)(void)) CallResolver("REALQDGlobals");
  104.     return pREALQDGlobals();
  105. }
  106.  
  107. int REALallocateMenuID(void)
  108. {
  109.     static int (*pREALallocateMenuID)(void);
  110.     if (!pREALallocateMenuID)
  111.         pREALallocateMenuID = (int (*)(void)) CallResolver("allocateMenuID");
  112.     return pREALallocateMenuID();
  113. }
  114.  
  115. void REALreleaseMenuID(int id)
  116. {
  117.     static int (*pREALreleaseMenuID)(int);
  118.     if (!pREALreleaseMenuID)
  119.         pREALreleaseMenuID = (int (*)(int)) CallResolver("releaseMenuID");
  120.     pREALreleaseMenuID(id);
  121. }
  122. #endif
  123.  
  124. void GraphicsDrawLine(Ptr graphicsObject, int x1, int y1, int x2, int y2)
  125. {
  126.     static void (*pDrawLine)(Ptr graphicsObject, int x1, int y1, int x2, int y2);
  127.     if (!pDrawLine)
  128.         pDrawLine = (void (*)(Ptr graphicsObject, int x1, int y1, int x2, int y2)) CallResolver("RuntimeGraphicsDrawLine");
  129.     pDrawLine(graphicsObject, x1, y1, x2, y2);
  130. }
  131.  
  132. void REALRegisterMethod(REALmethodDefinition *defn)
  133. {
  134.     static void (*pRuntimeRegisterMethod)(REALmethodDefinition *defn);
  135.     if (!pRuntimeRegisterMethod)
  136.         pRuntimeRegisterMethod = (void (*)(REALmethodDefinition *)) CallResolver("PluginRegisterMethod");
  137.  
  138. #ifdef USECALLSHELL
  139.     defn->function = buildEnvironmentShell(defn->function);
  140.     defn->setterFunction = buildEnvironmentShell(defn->setterFunction);
  141. #endif
  142.  
  143.     pRuntimeRegisterMethod(defn);
  144. }
  145.  
  146. void REALRegisterControl(REALcontrol *defn)
  147. {
  148.     static void (*pRuntimeRegisterControl)(REALcontrol *defn);
  149.     if (!pRuntimeRegisterControl)
  150.         pRuntimeRegisterControl = (void (*)(REALcontrol *)) CallResolver("PluginRegisterControl");
  151.  
  152. #ifdef USECALLSHELL
  153.     int i;
  154.     for (i = 0; i < defn->propertyCount; i++)
  155.     {
  156.         defn->properties[i].getter = buildEnvironmentShell(defn->properties[i].getter);
  157.         defn->properties[i].setter = buildEnvironmentShell(defn->properties[i].setter);
  158.     }
  159.     for (i = 0; i < defn->methodCount; i++)
  160.     {
  161.         defn->methods[i].function = buildEnvironmentShell(defn->methods[i].function);
  162.         defn->methods[i].setterFunction = buildEnvironmentShell(defn->methods[i].setterFunction);
  163.     }
  164.     defn->behaviour->constructorFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->constructorFunction);
  165.     defn->behaviour->destructorFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->destructorFunction);
  166.     defn->behaviour->redrawFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->redrawFunction);
  167.     defn->behaviour->clickFunction = (Boolean (*)(REALcontrolInstance, int, int, int)) buildEnvironmentShell(defn->behaviour->clickFunction);
  168.     defn->behaviour->mouseDragFunction = (void (*)(REALcontrolInstance, int, int)) buildEnvironmentShell(defn->behaviour->mouseDragFunction);
  169.     defn->behaviour->mouseUpFunction = (void (*)(REALcontrolInstance, int, int)) buildEnvironmentShell(defn->behaviour->mouseUpFunction);
  170.     defn->behaviour->gainedFocusFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->gainedFocusFunction);
  171.     defn->behaviour->lostFocusFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->lostFocusFunction);
  172.     defn->behaviour->keyDownFunction = buildEnvironmentShell(defn->behaviour->keyDownFunction);
  173.     defn->behaviour->openFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->openFunction);
  174.     defn->behaviour->closeFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->closeFunction);
  175.     defn->behaviour->backgroundIdleFunction = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->backgroundIdleFunction);
  176.     defn->behaviour->drawOffscreenFunction = (void (*)(REALcontrolInstance, REALgraphics)) buildEnvironmentShell(defn->behaviour->drawOffscreenFunction);
  177.     defn->behaviour->setSpecialBackground = (void (*)(REALcontrolInstance)) buildEnvironmentShell(defn->behaviour->setSpecialBackground);
  178. #endif
  179.  
  180.     pRuntimeRegisterControl(defn);
  181. }
  182.  
  183. void REALRegisterClassExtension(REALclassDefinition *defn)
  184. {
  185.     static void (*pRegisterClassExtension)(REALclassDefinition *defn);
  186.     if (!pRegisterClassExtension)
  187.         pRegisterClassExtension = (void (*)(REALclassDefinition *)) CallResolver("PluginRegisterClassExtension");
  188.  
  189. #ifdef USECALLSHELL
  190.     int i;
  191.     for (i = 0; i < defn->propertyCount; i++)
  192.     {
  193.         defn->properties[i].getter = buildEnvironmentShell(defn->properties[i].getter);
  194.         defn->properties[i].setter = buildEnvironmentShell(defn->properties[i].setter);
  195.     }
  196.     for (i = 0; i < defn->methodCount; i++)
  197.     {
  198.         defn->methods[i].function = buildEnvironmentShell(defn->methods[i].function);
  199.         defn->methods[i].setterFunction = buildEnvironmentShell(defn->methods[i].setterFunction);
  200.     }
  201. #endif
  202.  
  203.     if (pRegisterClassExtension)
  204.         pRegisterClassExtension(defn);
  205. }
  206.  
  207. void REALRegisterDBEngine(REALdbEngineDefinition *defn)
  208. {
  209.     static void (*pRegisterDatabaseEngine)(REALdbEngineDefinition *defn);
  210.     if (!pRegisterDatabaseEngine)
  211.         pRegisterDatabaseEngine = (void (*)(REALdbEngineDefinition *)) CallResolver("PluginRegisterDBEngine");
  212.  
  213. #ifdef USECALLSHELL
  214.     defn->closeDatabase = (void (*)(dbDatabase *)) buildEnvironmentShell(defn->closeDatabase);
  215.     defn->getTableSchemaCursor = (REALdbCursor (*)(dbDatabase *)) buildEnvironmentShell(defn->getTableSchemaCursor);
  216.     defn->getFieldSchemaCursor = (REALdbCursor (*)(dbDatabase *, REALstring)) buildEnvironmentShell(defn->getFieldSchemaCursor);
  217.     defn->directSQLSelect = (REALdbCursor (*)(dbDatabase *, REALstring)) buildEnvironmentShell(defn->directSQLSelect);
  218.     defn->directSQLExecute = (void (*)(dbDatabase *, REALstring)) buildEnvironmentShell(defn->directSQLExecute);
  219.     defn->createTable = (void (*)(dbDatabase *, REALstring, REALnewColumn *, unsigned char *, int)) buildEnvironmentShell(defn->createTable);
  220.     defn->addTableRecord = (void (*)(dbDatabase *, REALstring, REALcolumnValue *)) buildEnvironmentShell(defn->addTableRecord);
  221.     defn->getTableCursor = (REALdbCursor (*)(dbDatabase *, REALstring, REALgetColumn *, REALcolumnConstraints *)) buildEnvironmentShell(defn->getTableCursor);
  222. #endif
  223.  
  224.     if (pRegisterDatabaseEngine)
  225.         pRegisterDatabaseEngine(defn);
  226. }
  227.  
  228. void REALRegisterDBTable(REALdbTableDefinition *defn)
  229. {
  230.     static void (*pRegisterDBTable)(REALdbTableDefinition *defn);
  231.     if (!pRegisterDBTable)
  232.         pRegisterDBTable = (void (*)(REALdbTableDefinition *)) CallResolver("PluginRegisterDBTable");
  233.     if (pRegisterDBTable)
  234.         pRegisterDBTable(defn);
  235. }
  236.  
  237. void REALRegisterDBCursor(REALdbCursorDefinition *defn)
  238. {
  239.     static void (*pRegisterDBCursor)(REALdbCursorDefinition *defn);
  240.     if (!pRegisterDBCursor)
  241.         pRegisterDBCursor = (void (*)(REALdbCursorDefinition *)) CallResolver("PluginRegisterDBCursor");
  242.  
  243. #ifdef USECALLSHELL
  244.     defn->closeCursor = (void (*)(dbCursor *)) buildEnvironmentShell(defn->closeCursor);
  245.     defn->cursorColumnCount = (int (*)(dbCursor *)) buildEnvironmentShell(defn->cursorColumnCount);
  246.     defn->cursorColumnName = (REALstring (*)(dbCursor *, int column)) buildEnvironmentShell(defn->cursorColumnName);
  247.     defn->cursorRowCount = (int (*)(dbCursor *)) buildEnvironmentShell(defn->cursorRowCount);
  248.     defn->cursorColumnValue = (void (*)(dbCursor *, int, Ptr *, dbFieldType *, int *)) buildEnvironmentShell(defn->cursorColumnValue);
  249.     defn->cursorReleaseValue = (void (*)(dbCursor *)) buildEnvironmentShell(defn->cursorReleaseValue);
  250.     defn->cursorNextRow = (Boolean (*)(dbCursor *)) buildEnvironmentShell(defn->cursorNextRow);
  251.     defn->cursorDelete = (void (*)(dbCursor *)) buildEnvironmentShell(defn->cursorDelete);
  252.     defn->cursorDeleteAll = (void (*)(dbCursor *)) buildEnvironmentShell(defn->cursorDeleteAll);
  253. #endif
  254.  
  255.     if (pRegisterDBCursor)
  256.         pRegisterDBCursor(defn);
  257. }
  258.  
  259. void REALRegisterClass(REALclassDefinition *defn)
  260. {
  261.     static void (*pRegisterClass)(REALclassDefinition *defn);
  262.     if (!pRegisterClass)
  263.         pRegisterClass = (void (*)(REALclassDefinition *)) CallResolver("PluginRegisterClass");
  264.  
  265. #ifdef USECALLSHELL
  266.     int i;
  267.     defn->constructor = buildEnvironmentShell(defn->constructor);
  268.     defn->destructor = buildEnvironmentShell(defn->destructor);
  269.     for (i = 0; i < defn->propertyCount; i++)
  270.     {
  271.         defn->properties[i].getter = buildEnvironmentShell(defn->properties[i].getter);
  272.         defn->properties[i].setter = buildEnvironmentShell(defn->properties[i].setter);
  273.     }
  274.     for (i = 0; i < defn->methodCount; i++)
  275.     {
  276.         defn->methods[i].function = buildEnvironmentShell(defn->methods[i].function);
  277.         defn->methods[i].setterFunction = buildEnvironmentShell(defn->methods[i].setterFunction);
  278.     }
  279.     for (i = 0; i < defn->eventInstanceCount; i++)
  280.         defn->eventInstances[i].implementation = buildEnvironmentShell(defn->eventInstances[i].implementation);
  281. #endif
  282.  
  283.     if (pRegisterClass)
  284.         pRegisterClass(defn);
  285. }
  286.  
  287. const char *REALCString(REALstring str)
  288. {
  289.     static const char *(*pStringGetCString)(REALstring str);
  290.     if (!pStringGetCString)
  291.         pStringGetCString = (const char *(*)(REALstring)) CallResolver("StringGetCString");
  292.     return (const char *) pStringGetCString(str);
  293. }
  294.  
  295. const unsigned char *REALPString(REALstring str)
  296. {
  297.     static const unsigned char *(*pStringGetPString)(REALstring str);
  298.     if (!pStringGetPString)
  299.         pStringGetPString = (const unsigned char *(*)(REALstring)) CallResolver("StringGetPString");
  300.     return (const unsigned char *) pStringGetPString(str);
  301. }
  302.  
  303. REALstring REALBuildString(const char *contents, int length)
  304. {
  305.     static REALstring (*pREALBuildString)(const char *contents, int length);
  306.     if (!pREALBuildString)
  307.         pREALBuildString = (REALstring (*)(const char *, int)) CallResolver("REALBuildString");
  308.     return pREALBuildString(contents, length);
  309. }
  310.  
  311. void REALLockObject(REALobject obj)
  312. {
  313.     static void (*pREALLockObject)(REALobject);
  314.     if (!pREALLockObject)
  315.         pREALLockObject = (void (*)(REALobject)) CallResolver("REALLockObject");
  316.     pREALLockObject(obj);
  317. }
  318.  
  319. void REALUnlockObject(REALobject obj)
  320. {
  321.     static void (*pREALUnlockObject)(REALobject);
  322.     if (!pREALUnlockObject)
  323.         pREALUnlockObject = (void (*)(REALobject)) CallResolver("REALUnlockObject");
  324.     pREALUnlockObject(obj);
  325. }
  326.  
  327. void REALLockString(REALstring str)
  328. {
  329.     static void (*pREALLockString)(REALstring);
  330.     if (!pREALLockString)
  331.         pREALLockString = (void (*)(REALstring)) CallResolver("REALLockString");
  332.     pREALLockString(str);
  333. }
  334.  
  335. void REALUnlockString(REALstring str)
  336. {
  337.     static void (*pREALUnlockString)(REALstring);
  338.     if (!pREALUnlockString)
  339.         pREALUnlockString = (void (*)(REALstring)) CallResolver("REALUnlockString");
  340.     pREALUnlockString(str);
  341. }
  342.  
  343. REALproc REALInterfaceRoutine(REALobject obj, const char *interfaceName, const char *methodName)
  344. {
  345.     static REALproc (*pInterfaceRoutine)(REALobject, const char *, const char *);
  346.     if (!pInterfaceRoutine)
  347.         pInterfaceRoutine = (REALproc (*)(REALobject, const char *, const char *)) CallResolver("GetInterfaceRoutine");
  348.     return pInterfaceRoutine(obj, interfaceName, methodName);
  349. }
  350. #ifndef WIN32
  351. REALpicture REALBuildPictureFromPicHandle(PicHandle pic, Boolean bPassOwnership)
  352. {
  353.     static REALpicture (*pREALBuildPictureFromPicHandle)(PicHandle, Boolean);
  354.     if (!pREALBuildPictureFromPicHandle)
  355.         pREALBuildPictureFromPicHandle = (REALpicture (*)(PicHandle, Boolean)) CallResolver("REALBuildPictureFromPicHandle");
  356.     return pREALBuildPictureFromPicHandle(pic, bPassOwnership);
  357. }
  358.  
  359. REALpicture REALBuildPictureFromGWorld(GWorldPtr world, Boolean bPassOwnership)
  360. {
  361.     static REALpicture (*pREALBuildPictureFromGWorld)(GWorldPtr, Boolean);
  362.     if (!pREALBuildPictureFromGWorld)
  363.         pREALBuildPictureFromGWorld = (REALpicture (*)(GWorldPtr, Boolean)) CallResolver("REALBuildPictureFromGWorld");
  364.     return pREALBuildPictureFromGWorld(world, bPassOwnership);
  365. }
  366. #endif
  367.  
  368. REALpicture REALBuildPictureFromPictureDescription(REALpictureDescription *description, Boolean bPassOwnership)
  369. {
  370.     static REALpicture (*pREALBuildPictureFromPictureDescription)(REALpictureDescription *, Boolean);
  371.     if (!pREALBuildPictureFromPictureDescription)
  372.         pREALBuildPictureFromPictureDescription = (REALpicture (*)(REALpictureDescription *, Boolean)) CallResolver("REALBuildPictureFromPictureDescription");
  373.     return pREALBuildPictureFromPictureDescription(description, bPassOwnership);
  374. }
  375.  
  376. void REALLockPictureDescription(REALpicture pic, REALpictureDescription *description)
  377. {
  378.     static void (*pLockPictureDescription)(REALpicture, REALpictureDescription *);
  379.     if (!pLockPictureDescription)
  380.         pLockPictureDescription = (void (*)(REALpicture, REALpictureDescription *)) CallResolver("lockPictureDescription");
  381.     pLockPictureDescription(pic, description);
  382. }
  383.  
  384. void REALUnlockPictureDescription(REALpicture pic)
  385. {
  386.     static void (*pUnlockPictureDescription)(REALpicture);
  387.     if (!pUnlockPictureDescription)
  388.         pUnlockPictureDescription = (void (*)(REALpicture)) CallResolver("unlockPictureDescription");
  389.     pUnlockPictureDescription(pic);
  390. }
  391.  
  392. void REALPictureClearCache(REALpicture pic)
  393. {
  394.     static void (*pPictureClearCache)(REALpicture);
  395.     if (!pPictureClearCache)
  396.         pPictureClearCache = (void (*)(REALpicture)) CallResolver("REALPictureClearCache");
  397.     pPictureClearCache(pic);
  398. }
  399.  
  400. #ifdef WIN32
  401. void REALDrawPicturePrimitive(HDC hDC, REALpicture pic, const Rect *rBounds, int bTransparent)
  402. {
  403.     static void (*pDrawPicturePrimitive)(HDC, REALpicture, const Rect *, int);
  404.     if (!pDrawPicturePrimitive)
  405.         pDrawPicturePrimitive = (void (*)(HDC, REALpicture, const Rect *, int)) CallResolver("drawPicturePrimitive");
  406.     pDrawPicturePrimitive(hDC, pic, rBounds, bTransparent);
  407. }
  408. #else
  409. void REALDrawPicturePrimitive(REALpicture pic, const Rect *rBounds, int bTransparent)
  410. {
  411.     static void (*pDrawPicturePrimitive)(REALpicture, const Rect *, int);
  412.     if (!pDrawPicturePrimitive)
  413.         pDrawPicturePrimitive = (void (*)(REALpicture, const Rect *, int)) CallResolver("drawPicturePrimitive");
  414.     pDrawPicturePrimitive(pic, rBounds, bTransparent);
  415. }
  416. #endif
  417.  
  418. REALdbCursor REALdbCursorFromDBCursor(dbCursor *cursor, REALdbCursorDefinition *defn)
  419. {
  420.     static REALdbCursor (*pREALdbCursorFromDBCursor)(dbCursor *, REALdbCursorDefinition *);
  421.     if (!pREALdbCursorFromDBCursor)
  422.         pREALdbCursorFromDBCursor = (REALdbCursor (*)(dbCursor *, REALdbCursorDefinition *)) CallResolver("REALdbCursorFromDBCursor");
  423.     return pREALdbCursorFromDBCursor(cursor, defn);
  424. }
  425.  
  426. REALdbDatabase REALdbDatabaseFromDBDatabase(dbDatabase *database, REALdbEngineDefinition *defn)
  427. {
  428.     static REALdbDatabase (*pREALdbDatabaseFromDBDatabase)(dbDatabase *, REALdbEngineDefinition *);
  429.     if (!pREALdbDatabaseFromDBDatabase)
  430.         pREALdbDatabaseFromDBDatabase = (REALdbDatabase (*)(dbDatabase *, REALdbEngineDefinition *)) CallResolver("REALdbDatabaseFromDBDatabase");
  431.     return pREALdbDatabaseFromDBDatabase(database, defn);
  432. }
  433.  
  434. void *REALGetEventInstance(REALcontrolInstance instance, REALevent *event)
  435. {
  436.     static void *(*pGetEventInstance)(REALcontrolInstance instance, int builtHook);
  437. #ifdef powerc
  438.     if (!pGetEventInstance)
  439.         pGetEventInstance = (void *(*)(REALcontrolInstance,int)) CallResolver("GetEventInstancePPC");
  440.     return (void *) pGetEventInstance(instance, event->forSystemUse);
  441. #else
  442.     if (!pGetEventInstance)
  443.         pGetEventInstance = (void *(*)(REALcontrolInstance,int)) CallResolver("GetEventInstance");
  444.     return (void *) pGetEventInstance(instance, event->forSystemUse);
  445. #endif
  446. }
  447.  
  448. #ifndef WIN32
  449. void REALRegisterEventFilter(void (*callback)(EventRecord *event, long param), long param)
  450. {
  451.     static void (*pRegisterEventFilter)(void (*callback)(EventRecord *, long), long param);
  452. #ifdef powerc
  453.     if (!pRegisterEventFilter)
  454.         pRegisterEventFilter = (void (*)(void (*)(EventRecord *, long), long)) CallResolver("PluginRegisterEventFilterPPC");
  455. #else
  456.     if (!pRegisterEventFilter)
  457.         pRegisterEventFilter = (void (*)(void (*)(EventRecord *, long), long)) CallResolver("PluginRegisterEventFilter");
  458. #endif
  459.     pRegisterEventFilter(callback, param);
  460. }
  461. #endif
  462.  
  463. void *REALGetControlData(REALcontrolInstance instance, REALcontrol *defn)
  464. {
  465.     return ((Ptr) instance) + defn->forSystemUse;
  466. }
  467.  
  468. void *REALGetClassData(REALobject instance, REALclassDefinition *defn)
  469. {
  470.     return ((Ptr) instance) + defn->forSystemUse;
  471. }
  472.  
  473. void REALGetControlBounds(REALcontrolInstance instance, Rect *rBounds)
  474. {
  475.     static void (*pGetControlBounds)(REALcontrolInstance, Rect *);
  476.     if (!pGetControlBounds)
  477.         pGetControlBounds = (void (*)(REALcontrolInstance, Rect *)) CallResolver("GetControlBounds");
  478.     pGetControlBounds(instance, rBounds);
  479. }
  480.  
  481. Boolean REALGetControlVisible(REALcontrolInstance instance)
  482. {
  483.     static int (*pGetControlVisible)(REALcontrolInstance);
  484.     if (!pGetControlVisible)
  485.         pGetControlVisible = (int (*)(REALcontrolInstance)) CallResolver("GetControlVisible");
  486.     return pGetControlVisible(instance);
  487. }
  488.  
  489. Boolean REALGetControlEnabled(REALcontrolInstance instance)
  490. {
  491.     static int (*pGetControlEnabled)(REALcontrolInstance, long);
  492.     if (!pGetControlEnabled)
  493.         pGetControlEnabled = (int (*)(REALcontrolInstance, long)) CallResolver("controlEnabledGetter");
  494.     return pGetControlEnabled(instance, 0);
  495. }
  496.  
  497. void REALSetControlVisible(REALcontrolInstance instance, Boolean visible)
  498. {
  499.     static void (*pSetControlVisible)(REALcontrolInstance, int);
  500.     if (!pSetControlVisible)
  501.         pSetControlVisible = (void (*)(REALcontrolInstance, int)) CallResolver("SetControlVisible");
  502.     pSetControlVisible(instance, visible);
  503. }
  504.  
  505. REALgraphics REALGetControlGraphics(REALcontrolInstance instance)
  506. {
  507.     static REALgraphics (*pREALGetControlGraphics)(REALcontrolInstance);
  508.     if (!pREALGetControlGraphics)
  509.         pREALGetControlGraphics = (REALgraphics (*)(REALcontrolInstance)) CallResolver("REALGetControlGraphics");
  510.     return pREALGetControlGraphics(instance);
  511. }
  512.  
  513. #ifdef WIN32
  514. REALfolderItem REALFolderItemFromPath(const char *path)
  515. {
  516.     static REALfolderItem (*pFolderItemFromPath)(const char *);
  517.     if (!pFolderItemFromPath)
  518.         pFolderItemFromPath = (REALfolderItem (*)(const char *)) CallResolver("FolderItemFromPath");
  519.     return pFolderItemFromPath(path);
  520. }
  521. #else
  522. REALfolderItem REALFolderItemFromFSSpec(const FSSpec *spec)
  523. {
  524.     static REALfolderItem (*pFolderItemFromFSSpec)(const FSSpec *);
  525.     if (!pFolderItemFromFSSpec)
  526.         pFolderItemFromFSSpec = (REALfolderItem (*)(const FSSpec *)) CallResolver("FolderItemFromFSSpec");
  527.     return pFolderItemFromFSSpec(spec);
  528. }
  529.  
  530. Boolean REALFSSpecFromFolderItem(FSSpec *spec, REALfolderItem item)
  531. {
  532.     static Boolean (*pREALFSSpecFromFolderItem)(FSSpec *, REALfolderItem);
  533.     if (!pREALFSSpecFromFolderItem)
  534.         pREALFSSpecFromFolderItem = (Boolean (*)(FSSpec *, REALfolderItem)) CallResolver("REALFSSpecFromFolderItem");
  535.     return pREALFSSpecFromFolderItem(spec, item);
  536. }
  537. #endif
  538.  
  539. REALstring REALpathFromFolderItem(REALfolderItem item)
  540. {
  541.     static REALstring (*pREALpathFromFolderItem)(REALfolderItem);
  542.     if (!pREALpathFromFolderItem)
  543.         pREALpathFromFolderItem = (REALstring (*)(REALfolderItem)) CallResolver("REALpathFromFolderItem");
  544.     return pREALpathFromFolderItem(item);
  545. }
  546.  
  547. #ifdef WIN32
  548. HDC REALGraphicsDC(REALgraphics context)
  549. {
  550.     static HDC (*pREALGraphicsDC)(REALgraphics);
  551.     if (!pREALGraphicsDC)
  552.         pREALGraphicsDC = (HDC (*)(REALgraphics)) CallResolver("REALGraphicsDC");
  553.     return pREALGraphicsDC(context);
  554. }
  555. #else
  556. void REALSelectGraphics(REALgraphics context)
  557. {
  558.     static void (*pSelectGraphics)(REALgraphics);
  559.     if (!pSelectGraphics)
  560.         pSelectGraphics = (void (*)(REALgraphics)) CallResolver("SelectGraphics");
  561.     pSelectGraphics(context);
  562. }
  563.  
  564. void REALGraphicsDrawOffscreenMacControl(REALgraphics context, ControlHandle mh)
  565. {
  566.     static void (*pDrawOffscreenMacControl)(REALgraphics, ControlHandle);
  567.     if (!pDrawOffscreenMacControl)
  568.         pDrawOffscreenMacControl = (void (*)(REALgraphics, ControlHandle)) CallResolver("DrawOffscreenMacControl");
  569.     pDrawOffscreenMacControl(context, mh);
  570. }
  571. #endif
  572. void REALInvalidateControl(REALcontrolInstance instance)
  573. {
  574.     static void (*pInvalidateControl)(REALcontrolInstance);
  575.     if (!pInvalidateControl)
  576.         pInvalidateControl = (void (*)(REALcontrolInstance)) CallResolver("REALInvalidateControl");
  577.     pInvalidateControl(instance);
  578. }
  579.  
  580. void REALInvalidateControlRect(REALcontrolInstance instance, int left, int top, int right, int bottom)
  581. {
  582.     static void (*pInvalidateControlRect)(REALcontrolInstance, int, int ,int, int);
  583.     if (!pInvalidateControlRect)
  584.         pInvalidateControlRect = (void (*)(REALcontrolInstance, int, int ,int, int)) CallResolver("REALInvalidateControlRect");
  585.     pInvalidateControlRect(instance, left, top, right, bottom);
  586. }
  587.  
  588. void REALSetSpecialBackground(REALcontrolInstance instance)
  589. {
  590.     static void (*pREALSetSpecialBackground)(REALcontrolInstance);
  591.     if (!pREALSetSpecialBackground)
  592.         pREALSetSpecialBackground = (void (*)(REALcontrolInstance)) CallResolver("REALSetSpecialBackground");
  593.     pREALSetSpecialBackground(instance);
  594. }
  595.  
  596. REALwindow REALGetControlWindow(REALcontrolInstance instance)
  597. {
  598.     static REALwindow (*pGetControlWindow)(REALcontrolInstance);
  599.     if (!pGetControlWindow)
  600.         pGetControlWindow = (REALwindow (*)(REALcontrolInstance)) CallResolver("getControlWindow");
  601.     return pGetControlWindow(instance);
  602. }
  603. #ifndef WIN32
  604. REALsound REALBuildSoundFromHandle(Handle sound, Boolean bPassOwnership)
  605. {
  606.     static REALsound (*pREALBuildSoundFromHandle)(Handle, Boolean);
  607.     if (!pREALBuildSoundFromHandle)
  608.         pREALBuildSoundFromHandle = (REALsound (*)(Handle, Boolean)) CallResolver("REALBuildSoundFromHandle");
  609.     return pREALBuildSoundFromHandle(sound, bPassOwnership);
  610. }
  611.  
  612. REALappleEvent REALBuildAppleEvent(const AppleEvent *event, Boolean bPassOwnership)
  613. {
  614.     static REALappleEvent (*pREALBuildAppleEvent)(const AppleEvent *);
  615.     if (!pREALBuildAppleEvent)
  616.         pREALBuildAppleEvent = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAppleEvent");
  617.     return pREALBuildAppleEvent(event);
  618. }
  619.  
  620. REALappleEvent REALBuildAEDescList(const AppleEvent *event, Boolean bPassOwnership)
  621. {
  622.     static REALappleEvent (*pREALBuildAEDescList)(const AppleEvent *);
  623.     if (!pREALBuildAEDescList)
  624.         pREALBuildAEDescList = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAEDescList");
  625.     return pREALBuildAEDescList(event);
  626. }
  627.  
  628. REALappleEvent REALBuildAEObjSpecifier(const AppleEvent *event, Boolean bPassOwnership)
  629. {
  630.     static REALappleEvent (*pREALBuildAEObjSpecifier)(const AppleEvent *);
  631.     if (!pREALBuildAEObjSpecifier)
  632.         pREALBuildAEObjSpecifier = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAEObjSpecifier");
  633.     return pREALBuildAEObjSpecifier(event);
  634. }
  635.  
  636. AppleEvent *REALAccessAppleEvent(REALappleEvent event)
  637. {
  638.     static AppleEvent *(*pREALAccessAppleEvent)(REALappleEvent);
  639.     if (!pREALAccessAppleEvent)
  640.         pREALAccessAppleEvent = (AppleEvent *(*)(REALappleEvent)) CallResolver("REALAccessAppleEvent");
  641.     return pREALAccessAppleEvent(event);
  642. }
  643.  
  644. AppleEvent *REALAccessAppleEventReply(REALappleEvent event)
  645. {
  646.     static AppleEvent *(*pREALAccessAppleEventReply)(REALappleEvent);
  647.     if (!pREALAccessAppleEventReply)
  648.         pREALAccessAppleEventReply = (AppleEvent *(*)(REALappleEvent)) CallResolver("REALAccessAppleEventReply");
  649.     return pREALAccessAppleEventReply(event);
  650. }
  651.  
  652. WindowPtr REALGetWindowHandle(REALwindow window)
  653. {
  654.     static WindowPtr (*pREALGetWindowHandle)(REALwindow);
  655.     if (!pREALGetWindowHandle)
  656.         pREALGetWindowHandle = (WindowPtr (*)(REALwindow)) CallResolver("REALGetWindowHandle");
  657.     return pREALGetWindowHandle(window);
  658. }
  659.  
  660. ControlHandle REALGetControlHandle(REALcontrolInstance control)
  661. {
  662.     static ControlHandle (*pREALGetControlHandle)(REALcontrolInstance);
  663.     if (!pREALGetControlHandle)
  664.         pREALGetControlHandle = (ControlHandle (*)(REALcontrolInstance)) CallResolver("REALGetControlHandle");
  665.     return pREALGetControlHandle(control);
  666. }
  667.  
  668. MenuHandle REALGetPopupMenuHandle(REALpopupMenu popup)
  669. {
  670.     static MenuHandle (*pREALGetPopupMenuHandle)(REALpopupMenu);
  671.     if (!pREALGetPopupMenuHandle)
  672.         pREALGetPopupMenuHandle = (MenuHandle (*)(REALpopupMenu)) CallResolver("REALGetPopupMenuHandle");
  673.     return pREALGetPopupMenuHandle(popup);
  674. }
  675.  
  676. MovieController REALgetMoviePlayerController(REALmoviePlayer instance)
  677. {
  678.     static MovieController (*pREALgetMoviePlayerController)(REALmoviePlayer);
  679.     if (!pREALgetMoviePlayerController)
  680.         pREALgetMoviePlayerController = (MovieController (*)(REALmoviePlayer)) CallResolver("getMoviePlayerController");
  681.     return pREALgetMoviePlayerController(instance);
  682. }
  683.  
  684. Movie REALgetMovieMovie(REALmovie instance)
  685. {
  686.     static Movie (*pREALgetMovieMovie)(REALmovie);
  687.     if (!pREALgetMovieMovie)
  688.         pREALgetMovieMovie = (Movie (*)(REALmovie)) CallResolver("getMovieMovie");
  689.     return pREALgetMovieMovie(instance);
  690. }
  691.  
  692. REALmovie REALbuildMovie(Movie movie, short resRefNum, Boolean bNew)
  693. {
  694.     static REALmovie (*pREALbuildMovie)(Movie, int, int);
  695.     if (!pREALbuildMovie)
  696.         pREALbuildMovie = (REALmovie (*)(Movie, int, int)) CallResolver("buildMovie");
  697.     return pREALbuildMovie(movie, resRefNum, bNew);
  698. }
  699.  
  700. void REALmarkMovieDirty(REALmovie movie)
  701. {
  702.     static void (*pREALmarkMovieDirty)(REALmovie);
  703.     if (!pREALmarkMovieDirty)
  704.         pREALmarkMovieDirty = (void (*)(REALmovie)) CallResolver("markMovieDirty");
  705.     pREALmarkMovieDirty(movie);
  706. }
  707.  
  708. int REALenterMovies(void)
  709. {
  710.     static int (*pREALenterMovies)(void);
  711.     if (!pREALenterMovies)
  712.         pREALenterMovies = (int (*)(void)) CallResolver("REALenterMovies");
  713.     return pREALenterMovies();
  714. }
  715. #endif
  716.  
  717. REALobject REALnewInstance(const char *className)
  718. {
  719.     static REALobject (*pREALnewInstance)(const char *);
  720.     if (!pREALnewInstance)
  721.         pREALnewInstance = (REALobject (*)(const char *)) CallResolver("PluginNewInstance");
  722.     return pREALnewInstance(className);
  723. }
  724.  
  725. void REALSocketConnect(REALsocket socket, REALstring address, int port)
  726. {
  727.     static void (*pSocketConnect)(REALsocket, REALstring, int);
  728.     if (!pSocketConnect)
  729.         pSocketConnect = (void (*)(REALsocket, REALstring, int)) CallResolver("SocketDirectConnect");
  730.     pSocketConnect(socket, address, port);
  731. }
  732.  
  733. void REALSocketClose(REALsocket socket)
  734. {
  735.     static void (*pSocketClose)(REALsocket socket);
  736.     if (!pSocketClose)
  737.         pSocketClose = (void (*)(REALsocket)) CallResolver("socketClose");
  738.     pSocketClose(socket);
  739. }
  740.  
  741. REALstring REALSocketReadAll(REALsocket socket)
  742. {
  743.     static REALstring (*pSocketReadAll)(REALsocket);
  744.     if (!pSocketReadAll)
  745.         pSocketReadAll = (REALstring (*)(REALsocket)) CallResolver("SocketReadAll");
  746.     return pSocketReadAll(socket);
  747. }
  748.  
  749. REALstring REALSocketRead(REALsocket socket, int count)
  750. {
  751.     static REALstring (*pSocketRead)(REALsocket, int);
  752.     if (!pSocketRead)
  753.         pSocketRead = (REALstring (*)(REALsocket, int)) CallResolver("socketRead");
  754.     return pSocketRead(socket, count);
  755. }
  756.  
  757. void REALSocketWrite(REALsocket socket, REALstring data)
  758. {
  759.     static void (*pSocketClose)(REALsocket, REALstring);
  760.     if (!pSocketClose)
  761.         pSocketClose = (void (*)(REALsocket, REALstring)) CallResolver("SocketWrite");
  762.     pSocketClose(socket, data);
  763. }
  764.  
  765. int REALSocketLastErrorCode(REALsocket socket)
  766. {
  767.     static int (*pSocketLastErrorCode)(REALsocket, int);
  768.     if (!pSocketLastErrorCode)
  769.         pSocketLastErrorCode = (int (*)(REALsocket, int)) CallResolver("socketLastErrorCode");
  770.     return pSocketLastErrorCode(socket, 0);
  771. }
  772.  
  773. REALstring REALSocketLookahead(REALsocket socket)
  774. {
  775.     static REALstring (*pSocketLookahead)(REALsocket, int);
  776.     if (!pSocketLookahead)
  777.         pSocketLookahead = (REALstring (*)(REALsocket, int)) CallResolver("socketLookahead");
  778.     return pSocketLookahead(socket, 0);
  779. }
  780.  
  781. REALstring REALSocketLocalAddressGetter(REALsocket socket)
  782. {
  783.     static REALstring (*pSocketLocalAddressGetter)(REALsocket, int);
  784.     if (!pSocketLocalAddressGetter)
  785.         pSocketLocalAddressGetter = (REALstring (*)(REALsocket, int)) CallResolver("socketLookahead");
  786.     return pSocketLocalAddressGetter(socket, 0);
  787. }
  788.  
  789. void REALSocketPoll(REALsocket socket)
  790. {
  791.     static void (*pSocketPoll)(REALsocket);
  792.     if (!pSocketPoll)
  793.         pSocketPoll = (void (*)(REALsocket)) CallResolver("socketPoll");
  794.     pSocketPoll(socket);
  795. }
  796.  
  797. int REALSocketGetEvents(REALsocket socket)
  798. {
  799.     static int (*pSocketGetEvents)(REALsocket, int);
  800.     if (!pSocketGetEvents)
  801.         pSocketGetEvents = (int (*)(REALsocket, int)) CallResolver("socketGetEvents");
  802.     return pSocketGetEvents(socket, 0);
  803. }
  804.  
  805. void REALRegisterDataSourceInterface(const char *szMenuName, void (*proc)(void))
  806. {
  807.     static void (*pRegisterDataSourceInterface)(const char *, void (*proc)(void));
  808.     if (!pRegisterDataSourceInterface)
  809.         pRegisterDataSourceInterface = (void (*)(const char *, void (*proc)(void))) CallResolver("RegisterDataSourceInterface");
  810.     if (pRegisterDataSourceInterface)
  811.         pRegisterDataSourceInterface(szMenuName, proc);
  812. }
  813.  
  814. void REALRegisterDataSource(const char *szDatasourceName, REALdbDatabase (*proc)(Ptr data, int dataLen))
  815. {
  816.     static void (*pRegisterDataSource)(const char *, REALdbDatabase (*)(Ptr data, int dataLen));
  817.     if (!pRegisterDataSource)
  818.         pRegisterDataSource = (void (*)(const char *, REALdbDatabase (*)(Ptr data, int dataLen))) CallResolver("RegisterDataSource");
  819.     pRegisterDataSource(szDatasourceName, proc);
  820. }
  821.  
  822. void REALDesignAddDataSource(const char *baseName, const char *szDataSourceName, Ptr data, int dataLen)
  823. {
  824.     static void (*pDesignAddDataSource)(const char *, const char *, Ptr, int);
  825.     if (!pDesignAddDataSource)
  826.         pDesignAddDataSource = (void (*)(const char *, const char *, Ptr, int)) CallResolver("DesignAddDataSource");
  827.     if (pDesignAddDataSource)
  828.         pDesignAddDataSource(baseName, szDataSourceName, data, dataLen);
  829. }
  830.  
  831. #ifdef WIN32
  832.  
  833. extern "C" {
  834. void __declspec(dllexport) REALPluginMain(void *(*resolver)(const char *entryName));
  835. }
  836.  
  837. void __declspec(dllexport) REALPluginMain(void *(*resolver)(const char *entryName))
  838. #else
  839. void main(void *(*resolver)(const char *entryName))
  840. #endif
  841. {
  842. //    short *glue;
  843. //    int i;
  844. //    void (*pRegisterPluginExports)(REALexport *table);
  845.     void (*pRegisterPluginVersion)(int version);
  846.  
  847. #ifndef WIN32
  848.     EnterCodeResource();
  849. #endif
  850.     gResolver = resolver;
  851.  
  852. #ifdef USECALLSHELL
  853.     unsigned long (*getA4stack)(void);
  854.  
  855.     getA4stack = (unsigned long(*)(void)) resolver("getA4stackReference");
  856.     a4stack = getA4stack();
  857. #else
  858. #ifndef WIN32
  859.     gResolverPPC = (void *(*)(const char *)) CallUniversalProc((RoutineDescriptor *) gResolver, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)), "ResolverPPC");
  860. #endif
  861. #endif
  862.  
  863. //    pRegisterPluginExports = (void (*)(REALexport *)) CallResolver("RegisterPluginExports");
  864. //    pRegisterPluginExports(pluginExports);
  865.  
  866.     pRegisterPluginVersion = (void (*)(int)) CallResolver("RegisterPluginVersion");
  867.     pRegisterPluginVersion(kCurrentREALControlVersion);
  868.  
  869.     PluginEntry();
  870.  
  871. #ifndef WIN32
  872.     ExitCodeResource();
  873. #endif
  874. }
  875.  
  876. long REALstringStruct::Length(void)
  877. {
  878.     if (this)
  879.         return mPrivateLength;
  880.     else
  881.         return 0;
  882. }
  883.  
  884. const char *REALstringStruct::CString()
  885. {
  886.     if (this)
  887.         return (const char *) (mPrivateStringData + 1);
  888.     else
  889.         return "";
  890. }
  891.  
  892. const unsigned char *REALstringStruct::PString()
  893. {
  894.     if (this)
  895.         return mPrivateStringData;
  896.     else
  897.         return "\p";
  898. }
  899.